/*
 * @Author: liuxinyea
 * @Date: 2024-08-08 23:05:01
 * @LastEditors: liuxinyea
 * @LastEditTime: 2024-08-11 23:08:49
 * @Description: 描述
 */
import { _decorator, CCInteger, Component, Label, Node } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('SunManager')
export class SunManager extends Component {
    private static _instance: SunManager = null;
    @property(CCInteger)
    private sunPoint:number = 0; //阳光值
    @property(Label)
    private sunPointLabel: Label = null;
    public get SunPoint(): number {
        return this.sunPoint;
    }
    public static get instance(): SunManager {
        return this._instance;
    }
    protected onLoad(): void {
        if (SunManager._instance == null) {
            SunManager._instance = this;
        }else{
            console.log("SunManager is already exist");
            this.node.destroy();
        }
    }
    protected start(): void {
        this.updateSunPointLabel()
    }
    /**
     * 更新阳光值
     */
    updateSunPointLabel() {
        this.sunPointLabel.string = this.sunPoint.toString();
    }
    /**
     * 减少阳光
     * @param point 减少的阳光值
     */
    public subPoint(point:number) {
        this.sunPoint -= point;
        if(this.sunPoint < 0){
            this.sunPoint = 0;
        }
        this.updateSunPointLabel();
    } 
    public addPoint(point: number) {
        this.sunPoint += point;
        this.updateSunPointLabel();
    }
}

